<?php
declare (strict_types = 1);
namespace app\adminapi\controller\system\auth;
use adminmatrix\server\app\server\JsonService;
use think\exception\HttpException;
use think\Request;
use adminmatrix\server\app\adminMatrix;
use think\response\Json;
use adminmatrix\annotation\auth\IsPermission;
use app\adminapi\logic\system\auth\PermissionLogic as LogicPermission;
class PermissionController extends AdminMatrix
{
    public function lists(Request $request)
    {
        return $this->dataLists();
    }

     public function save(Request $request , LogicPermission $logic) : Json
     {
         try {
             $logic -> save($request);
             return  JsonService::success("新增成功");
         } catch (HttpException $e)
         {
             return JsonService::fail($e->getMessage());
         }
     }



     public function update( Request $request , LogicPermission $logic) : Json
     {
         try {
             $logic->update($request);
             return JsonService::success('更新成功');
         } catch (HttpException $e)
         {
             return JsonService::fail($e->getMessage());
         }
     }

     public function delete(int $id , Request $request , LogicPermission $logic) : Json
     {
         try {
             $logic->delete($id);
             return JsonService::success('删除成功');
         } catch (HttpException $e)
         {
             return JsonService::fail($e->getMessage());
         }
     }

    #[IsPermission]
    public function tree( Request $request , LogicPermission $logic ) : Json
    {
        try {
            $params = $logic->tree($request);
            return JsonService::success($params);
        } catch (HttpException $e)
        {
            return  JsonService::fail($e->getMessage());
        }
    }


    #[IsPermission]
    public function treeAll( Request $request , LogicPermission $logic ) : Json
    {
        try {
            $params = $logic->treeAll($request);
            return JsonService::success($params);
        } catch (HttpException $e)
        {
            return  JsonService::fail($e->getMessage());
        }
    }
}